﻿Imports DNP.GestionComercial.FormBase
Imports DNP.GestionComercial.Util
Imports DNP.GestionComercial.BE
Imports DNP.GestionComercial.BL
Imports Scripting
Public Class frmPagarVenta
#Region "Declaracion de variables"
    Dim oMsg As New sisMensaje
    Dim oVenta As New VentaBE
    Dim _descripcion As String = ""
    Dim _frm As New Windows.Forms.Form
    Dim vFormBase As frmFormBase = New frmFormBase

#End Region
#Region "Inicializar Pagina"
    Public Sub New(ByRef objeto As VentaBE, ByRef frm As Windows.Forms.Form)

        oVenta = objeto
        _frm = frm
        InitializeComponent()
        InicializarControles()

    End Sub
    Private Sub InicializarControles()
        lblPagoTotal.Text = oVenta.NVEN_TOTAL.ToString
        lblPagoVuelto.Text = ""

    End Sub

#End Region
#Region "Funciones"


#End Region
#Region "Accion Botones"


#End Region
#Region "Operaciones"
    Private Function validarDatos() As Boolean
        If rbEfectivo.Checked Then
            If vFormBase.ValidarStringVacio(txtPagoEfectivo.Text, "Monto Efectivo", True) = "" Then
                txtPagoEfectivo.Focus()
                Return False
            End If
        End If
        Return True
    End Function
    Private Sub guardar()
        If Not validarDatos() Then
            vFormBase.showError()
            vFormBase.objListaError = New TError
            Return
        End If
        RecuperarDatos()
        Dim orespuesta As New RespuestaBE
        orespuesta = New VentasBL().Guardar(oVenta, "U60546")
        If orespuesta.Respuesta Then
            oMsg.showMsgInformation("msgExitoGuardar")
        Else
            oMsg.showMsgWarning("msgErrorGuardar")
        End If

    End Sub
    Private Sub RecuperarDatos()
        oVenta.NCLI_CODIGO = IIf(txtCodCliente.Text = "", 0, Val(txtCodCliente.Text))
        oVenta.NEMP_CODIGO = 0
        oVenta.DVEN_FECHA = Nothing
        oVenta.NVEN_ESTADO = "1" ' activo
        oVenta.NVEN_TIP_COMP = 1 'boleta
        If rbEfectivo.Checked Then
            oVenta.NVEN_FORMA_PAGO = 1 ' efectivo
        Else
            oVenta.NVEN_FORMA_PAGO = 2 ' tarjeta
        End If
        oVenta.NVEN_TIP_COMP = 1 ' Boleta
        If oVenta.NVEN_TIP_COMP = 2 Then ' es fatura
            oVenta.NVEN_IGV = 0.19 * oVenta.NVEN_TOTAL
        Else
            oVenta.NVEN_IGV = 0
            oVenta.NVEN_SUBTOTAL = oVenta.NVEN_TOTAL - oVenta.NVEN_IGV
        End If
        oVenta.NVEN_SUBTOTAL = oVenta.NVEN_TOTAL - oVenta.NVEN_IGV
    End Sub

#End Region
#Region "Eventos Controles "
    Private Sub txtCodCliente_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtCodCliente.KeyDown
        If e.KeyValue = sisEnum.TeclasComunes.AbrirFormBusqueda Then
            Dim buscarCliente As New frmBusCliente(Me)
            buscarCliente.ShowDialog()
            If (buscarCliente.DialogResult = Windows.Forms.DialogResult.OK) Then
                txtCodCliente.Text = Convert.ToString(buscarCliente.vRespuesta.PARAMETRO01)
                txtNombreCliente.Text = Convert.ToString(buscarCliente.vRespuesta.PARAMETRO02)
            End If
        End If
    End Sub
    Private Sub txtPagoEfectivo_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPagoEfectivo.KeyPress
        If (e.KeyChar = Microsoft.VisualBasic.ChrW(13)) Then
            lblPagoVuelto.Text = oVenta.NVEN_TOTAL - CDbl(txtPagoEfectivo.Text)
        End If
    End Sub
    Private Sub btnPagar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPagar.Click
        Guardar()

    End Sub
#End Region
  
    
 
  
End Class